﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using AMG.Model;
using AMG.BLL.User;
using AMG.Common;
using AMG.Config;
using AMG.DALProfile;
using System.Text;
using System.IO;

namespace AMG.Web
{
    public partial class _Default : AMG .Web.UI.Page.BasePage
    {
        protected string email = string.Empty;
        protected int flag = -1;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.Form["UserName"] == null || Request.Form["Password"] == null
                    || Request.Form["UserName"].Trim() == string.Empty || Request.Form["Password"].Trim() == string.Empty)
                {
                    flag = -2;
                    if (Request.QueryString["a"] == "relog")
                        flag = -2;
                }
                else
                {
                    email = Request.Form["UserName"].Trim();
                    string Password = Request.Form["Password"].Trim();
                    BLL.User.User us = new AMG.BLL.User.User();
                    string userName = string.Empty;
                    string userPortrait = string.Empty;
                    EnumLoginState state = us.Login(email , Password);
                    switch (state)
                    {
                        case EnumLoginState.Succeed:
                            //这里开始整合DZ NT登录

                            AMG.Web.UI.Page.UserPage.SetCookie(int.Parse (email), Input.MD5(Password, false));
                            Response.Redirect("webform1.aspx");  
                            //Response.Write("<script language=\"javascript\">window.top.location.href='default.aspx';</script>");                                                       
                            break;
                        case EnumLoginState.Err_UnActivation:
                            flag = 1;
                            break;
                        case EnumLoginState.Err_NameOrPwdError:
                            flag = 0;
                            break;
                        case EnumLoginState.Err_Locked:
                            Response.Redirect("/ErrorPage.aspx?r=对不起，您的帐号已经被系统锁定，如有疑问，请与管理员联系");
                            break;
                    }
                }
                DataBind();
            }
        }
    }
}
